class MasterSlaveDBRouter(object):
    """数据库读写路由"""

    def db_for_read(self, model, **hints):
        """读"""

        print('读取数据, 使用 slave数据库')
        return "slave"

    def db_for_write(self, model, **hints):
        """写"""
        print('写入数据, 使用 master数据库')

        # if model._meta.model_name == 'bookinfo':
        #     return 'book'
        # if model._meta.model_name == 'heroinfo':
        #     return 'hero'

        return "default"

    def allow_relation(self, obj1, obj2, **hints):
        """是否运行关联操作"""
        return True
